package gui.utils;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class TransparentLine {

	private Graphics g;
	private float alpha;
	private Color color;
	private int x0;
	private int y0;
	private int x1;
	private int y1;


	public TransparentLine(Graphics g, float alpha, int x0, int y0, int x1, int y1, Color color){
		this.setG(g);
		this.setAlpha(alpha);
		this.setColor(color);
		this.x0=x0;
		this.y0=y0;
		this.x1=x1;
		this.y1=y1;
		drawLine();
	}


	private void drawLine() {
		Graphics2D g2d = (Graphics2D)g;
		g2d.setComposite(makeComposite(this.alpha));
		g2d.setPaint(this.color);
		g2d.drawLine(x0, y0, x1, y1);
	}



	private AlphaComposite makeComposite(float alpha) {
		int type = AlphaComposite.SRC_OVER;
		return(AlphaComposite.getInstance(type, alpha));
	}


	public void setColor(Color color) {
		this.color = color;
	}


	public Color getColor() {
		return color;
	}


	public void setAlpha(float alpha) {
		this.alpha = alpha;
	}


	public float getAlpha() {
		return alpha;
	}


	public void setG(Graphics g) {
		this.g = g;
	}


	public Graphics getG() {
		return g;
	}
}
